package com.foodplus.www.foodplus;

import android.app.Activity;
import android.app.Application;
import android.content.SharedPreferences;

import com.foodplus.www.api.RetrofitManager;

/**
 * Created by WangZhiChao on 2016/10/31.
 */

public class MyApp extends Application {


    private static MyApp app = null;

    private SharedPreferences UserPreferences;

    private boolean BasketEditting = false;

    public MyApp() {
        app = this;
    }

    public static MyApp getInstance() {
        return app;
    }


    @Override
    public void onCreate() {
        super.onCreate();
        RetrofitManager.getInstance().initRetrofit();

    }

    public boolean isLoggedIn() {
        return getUserPreferences().getBoolean("loginState", false);
    }

    public String getKey() {
        return getUserPreferences().getString("key", "");
    }

    public void setLoggedIn(boolean loggedIn) {
        getUserPreferences().edit().putBoolean("loginState", loggedIn).apply();
    }

    public String getToken() {
        return "749a036dc06ae8b3a120848995a9f306";
    }

    public SharedPreferences getUserPreferences() {
        if (UserPreferences == null) {
            UserPreferences = getSharedPreferences("userData", Activity.MODE_PRIVATE);
        }
        return UserPreferences;
    }


    public void setBasketEditting(boolean basketEditting) {
        BasketEditting = basketEditting;
    }

    public boolean isBasketEditting() {
        return BasketEditting;
    }


}
